<template>
  <div>
    <!--条件筛选-->
    <TopFilter ref="topFilter" :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>

    <button-area :style="{ paddingLeft: '80px' }"></button-area>
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :isSelectColumn="false"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="arr => (this.selectColumn = arr)"
    >
    <template slot="controls" slot-scope="props">
        <multiuse-button size="small" type="primary" :click="downHandle">导出</multiuse-button>
      </template>
    </FilterTable>
    <!-- 编辑窗口 -->
    <!-- <Drawer
      :visible.sync="visibleDrawer"
      title="PDI检查项目维护"
      :width="1200"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
       >
      <info-model v-model="initData" @close="infoClose" />
    </Drawer> -->
    <Drawer :visible.sync="visibleDrawer" title="PDI检查单明细" width="1200" destroyOnClose :containerStyle="{}">
    <!-- <Drawer :visible.sync="visibleDrawer" :title="'PDI检查单明细'" destroyOnClose width="60%" :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }"> -->
      <pdiCheck @close="closePdi"  :top="top"  :selectColumn="selectColumn"></pdiCheck>

    </Drawer>

    <!-- <BaseDialog :visible.sync="visbleVehicle" title="车辆选择"
                :containerStyle="{ height: '80vh', overflow: 'auto', paddingBottom: '10px' }"
                destroyOnClose>
      <add-vehicle
        selectionType="single"
        @selectArr="selectVehicleFun"
        @closeDialog='visbleVehicle = false'></add-vehicle>
    </BaseDialog> -->

    <BaseDialog
      :visible.sync="issearch"
      :title="'服务中心查询'"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <ownerSeacher  @close="dealercloseHandler" />
    </BaseDialog>
  </div>
</template>

<script>
import ownerSeacher from '@/pages/repair/repairManage/PDIQueryPage/common/ownerSeacher';
import { exportExcelFile } from '@/utils';
//src\api\repair\PDIMessageForFactory\index.js
import {  exporturl} from '@/api/omSale/ActualSales/RetailOrders';
import { queryPDIInfoByPage,excelForQueryPageInfo } from '@/api/repair/PDIMessageForFactory/index';
import { dictionary } from '@/utils/dictMixin';
// import { getCurrentUser } from '@/api/cms-api/origin/construct/dealer';
import pdiCheck from '@/pages/repair/repairManage/PDIQueryPage/common/pdiCheck';
export default {
  name: 'pdiquerypage',
  mixins: [dictionary],
  components: {
    ownerSeacher,
    pdiCheck
  },
  data() {
    return {
      topFilterList: this.createTopFilterList(),
      columns: this.createTableColumns(),
      fetchParams: { xhrAbort: true, status:1 },
      visibleDrawer: false,
      fetchApi: queryPDIInfoByPage,
      visbleVehicle: false,
      initData: {},
      selectColumn: [],
      top:{},
      issearch: false,
      flag:false
    }
  },
  created() {
    //this.initColunm()
    //this.findUser()
  },
  methods: {
    // async initColunm() {
    //   this.columns.find(x => x.dataIndex == 'fwdjzt').dictItems = this.createDictList('5010')
    //   this.columns.find(x => x.dataIndex == 'fwdjlx').dictItems = this.createDictList('5009')
    // },
    // findUser(){
    //       // 获取当前登录人信息
    //       getCurrentUser({}).then(response=>{
    //         this.flag=response.data.appId==='beijing'? false:true
    //         if (this.flag){
    //           this.columns.find(x => x.dataIndex == 'dealerCode').hidden = false
    //           this.columns.find(x => x.dataIndex == 'dealerName').hidden = false
    //         }else{
    //           this.columns.find(x => x.dataIndex == 'dealerCode').hidden = true
    //           this.columns.find(x => x.dataIndex == 'dealerName').hidden = true
    //         }
    //   })
    // },
    closePdi(val) {
      // if(val === 'refresh'){
      //   this.fetchParams = { ...this.fetchParams };
      // }
      this.visibleDrawer = false
    },
    
    createTopFilterList() {
      return [
          {
          type: 'INPUT',
          label: '服务中心代码',
          fieldName: 'dealerCode',
          placeholder: '请选择',
          unitRender: () => {
            return (
              <div>
                <el-button icon="el-icon-search" onClick={() => this.seacherFun()}></el-button>
              </div>
            );
          },
          change:p=>{
            if(!p){
              this.dealerCode=''
            }
          }
        },
        {
          type: 'INPUT',
          label: 'VIN:',
          fieldName: 'vin'
        },
        // {
        //   type: 'INPUT',
        //   label: '车型',
        //   fieldName: 'fwchex',
        //   placeholder: '请选择',
        //   initialValue: '',
        //   unitRender: () => {
        //     return (
        //       <div>
        //         <el-button icon="el-icon-search" onClick={() => this.visbleVehicle = true}></el-button>
        //       </div>
        //     );
        //   },
        // },
        {
          type: 'SELECT',
          label: 'PDI类型:',
          fieldName: 'pdiType',
          placeholder: '请选择...',
          itemList: this.createDictList('4003')
        },
        // {
        //   type: 'RANGE_DATE',
        //   label: '生产日期',
        //   fieldName: 'productDate1|productDate2',
        //   valueFormat: 'yyyy-MM-dd',
        //   placeholder: '请选择'
        // },
        {
          type: 'RANGE_DATE',
          label: '检查日期',
          fieldName: 'pdiEntryDateBegin|pdiEntryDateEnd',
          valueFormat: 'yyyy-MM-dd',
          placeholder: '请选择'
        },
        // {
        //   type: 'SELECT',
        //   label: '状态:',
        //   fieldName: 'fwdjzt',
        //   placeholder: '请选择...',
        //   itemList: this.createDictList('5010')
        // },
      ]
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          align: "center",
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 50,
          align: "center",
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button  size="mini" type="text" onClick={() => this.detailHandle(props.row, 'detail')}>
                  查看
                </multiuse-button>
              </div>
            );
          }
        },
        // {
        //   title: '状态',
        //   dataIndex: 'fwdjzt',
        //   sorter: true,
        //   render: props => {    //编码转汉字
        //     return <span>{this.createDictText(props.row.fwdjzt, '5010')}</span>;
        //   }
        // },
        // {
        //   title: '服务中心代码',
        //   dataIndex: 'ownerCode2',
        //   sorter: true,
        //   width: 160
        // },
        // {
        //   title: '服务中心代码',
        //   dataIndex: 'dealerCode',
        //   width: 90,
        //   align: "center",
        //   showOverflowTooltip: true
        // },
        {
          title: '服务中心名称',
          dataIndex: 'dealerName',
          width: 180,
          align: "center",
          showOverflowTooltip: true
        },
        {
          title: 'PDI类型',
          dataIndex: 'pdiTypeName',
          width: 100,
          align: "center",
          //showOverflowTooltip: true
          // render: props => {    //编码转汉字
          //   return <span>{this.createDictText(props.row.pdiType, '2666')}</span>;
          // }
        },
        {
          title: 'PDI单号',
          dataIndex: 'pdNo',
          width: 180,
          align: "center",
          showOverflowTooltip: true
        },
        {
          title: 'VIN',
          dataIndex: 'vin',
          width: 180,
          align: "center",
          showOverflowTooltip: true
        },
        {
          title: '品牌',
          dataIndex: 'brandName',
          width: 120,
          align: "center",
          showOverflowTooltip: true
        },
        {
          title: '车系',
          dataIndex: 'seriesName',
          width: 120,
          align: "center",
          showOverflowTooltip: true
        },
        {
          title: '车型',
          dataIndex: 'modelName',
          width: 120,
          align: "center",
          showOverflowTooltip: true
        },
        // {
        //   title: '电机号',
        //   dataIndex: 'dianji',
        //   width: 120,
        //   align: "center",
        //   showOverflowTooltip: true
        // },
        // {
        //   title: '生产日期',
        //   dataIndex: 'fwscrq',
        //   sorter: true,
        //   dateFormat: 'yyyy-MM-dd hh:mm:ss',
        // },
        // {
        //   title: '发动机号/电机号',
        //   dataIndex: 'fwfdjh',
        //   sorter: true,
        // },
        // {
        //   title: '处理人',
        //   dataIndex: 'fwclryStr',
        //   sorter: true,
        // },
        // {
        //   title: '处理时间',
        //   dataIndex: 'fwclsj',
        //   sorter: true,
        //   dateFormat: 'yyyy-MM-dd hh:mm:ss',
        // },
        // {
        //   title: '创建人',
        //   dataIndex: 'createdByStr',
        //   width: 120,
        //   align: "center",
        //   showOverflowTooltip: true
        // },
        {
          title: '检查日期',
          dataIndex: 'pdiEntryDate',
          width: 200,
          align: "center",
          showOverflowTooltip: true,
          dateFormat: 'yyyy-MM-dd hh:mm:ss',
        },
        // {
        //   title: '修改日期',
        //   dataIndex: 'updatedAt',
        //   sorter: true,
        //   dateFormat: 'yyyy-MM-dd hh:mm:ss',
        // },
        // {
        //   title: '修改人',
        //   dataIndex: 'updatedByStr',
        //   sorter: true,
        // },
      ]
    },

    // pdi导出
    async downHandle() {
      let json = Object.assign({}, { CODE: 'CODE_00000270' }, this.fetchParams);
      let res = await exporturl(json);
      if (res.resultCode == 200) {
        this.$router.push('/admin/auth/oem/downloadCenter');
      }
    },
    changeHandle(val) {
      val.createdAt2 && (val.createdAt2 = val.createdAt2.split(' ')[0] + ' 23:59:59');
      val.productDate2 && (val.productDate2 = val.productDate2.split(' ')[0] + ' 23:59:59');
      //Object.assign({}, val);(浅拷贝) 将所有可枚举属性的值从一个或多个源对象赋值给目标对象，它将返回目标对象 {}为目标对象 val为源对象
      this.fetchParams = Object.assign({}, val);// 将val赋值给fetchParams
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    selectData(val) {
      this.tableData = val;
    },
    detailHandle(e) {
      // if (row.fwdjzt === 50101002) {
      //   type = 'show'
      // }
      console.info(e+"---------------------------------row")
      this.top = e;
      this.visibleDrawer = true;
    },
    // infoClose(rData) {
    //   this.visibleDrawer = false;
    //   if (rData.type === 'refresh') {
    //     // 重新加载
    //     this.fetchParams = { ...this.fetchParams };
    //   }
    // },
    // selectVehicleFun(arr) {
    //   this.vehicle = arr[0]
    //   this.visbleVehicle = false
    //   this.topFilterList.forEach(x => {
    //     if (x.fieldName === 'fwvinm') {
    //       x.initialValue = this.vehicle.fwvinm
    //     }
    //     if (x.fieldName === 'fwchex') {
    //       x.initialValue = this.vehicle.fwchex
    //     }
    //   })
    // },
    seacherFun(){
      this.issearch=true;
    },
    dealercloseHandler(val){
      console.info(val)
      if(val){
        this.topFilterList.find(x=>x.fieldName=='dealerCode').initialValue=val.dealerCode;
        // this.fetchParams=Object.assign({
        //   dealerCode: val.dealerCode
        // },this.fetchParams)
        this.dealerCode=val.dealerCode
      }
      this.issearch=false;
    }
  }
}
</script>
